<template>
	<view class="member-container">
		<view class="user-section">
			<view class="user-info-box" v-if="token" style="margin-top: 30rpx;">
				<navigator url="/pages/member/info/info" class="user-head">
					<image
						:src="memberInfo.user_headimg ? $util.img(memberInfo.user_headimg) : $util.img('upload/uniapp/default_head.png')"
						mode="aspectFill"></image>
				</navigator>
				<view class="user-box">
					<text class="user-title">{{ memberInfo.nick_name }}</text>
						
					<navigator v-if="memberLevelInfo.level_info.level_name" url="/pages/member/level/level"
						class="user-label">
						{{ memberLevelInfo.level_info.level_name }}    <span style="margin-left: 20rpx;">积分:{{point}}</span>
					</navigator>
				</view>
				
				
			</view>
			<view class="user-info-box no-log" v-if="!token" @click="clickLogin">
				<view class="user-head">
					<image :src="$util.img('upload/uniapp/default_head.png')"></image>
				</view>
				<view class="user-box" style="margin-top: 50rpx;">
					<text class="user-title">立即登录</text>
					<text class="user-desc">登录体验更多功能</text>
				</view>
			</view>
			<view class="user-set" style="display: flex;">
				<navigator url="/pages/member/info/info" v-if="token">
					<image :src="$util.img('upload/uniapp/member/member_set_up.png')"></image>
				</navigator>
			</view>
			<!-- <view class="member-sction" style="display: flex; justify-content: start;">
				<view class="sction-item" @click="redirectToLink('/pages/member/balance/balance')">
					<text class="num">{{ memberAccountInfo.balance }}</text>
					<text>余额</text>
				</view>
				<text class="shu"></text>
				<view class="sction-item" @click="redirectToLink('/pages/member/point/point')">
					<text class="num">{{ memberAccountInfo.point }}</text>
					<text>积分</text>
				</view>
				<text class="shu"></text>
				<view class="sction-item" @click="redirectToLink('/pages/member/coupon/coupon')">
					<text class="num">{{ couponNum }}</text>
					<text>优惠券</text>
				</view>
			</view> -->
			<navigator class="member-equity" v-if="token" style="margin-top: 30rpx;">
				<!-- <navigator class="member-equity" url="/pages/member/level/level" v-if="token"> -->
				<text class="level-img"></text>
				<text class="member-level">{{ memberLevelInfo.level_info.level_name }}</text>
				<!-- <text class="iconfont iconright">会员等级更多权益</text> -->
			</navigator>
		</view>
		<view class="member-body">
			<view class="order-section">
				<!-- <view class="order-head" @click="redirectToLink('/pages/order/list/list')">
					<text class="order-tit">全部订单</text>
					<text class="order-tip">查看全部订单</text>
					<text class="order-more iconfont">&#xe6a3;</text>
				</view> -->
				<view class="order-body">
					<view class="order-item" @click="redirectToLink('/pages/order/list/list?status=0')">
						<view class="order-icon">
							<text v-if="orderNum.waitPay > 99" class="order-num">99+</text>
							<text v-else-if="orderNum.waitPay > 0" class="order-num">{{ orderNum.waitPay }}</text>
							<!-- <text class="iconfont">&#xe674;</text> -->
							<image :src="$util.img('upload/uniapp/member/daifukuan.png')" mode="aspectFill"></image>

						</view>
						<text class="order-name">待付款</text>
					</view>
					<view class="order-item" @click="redirectToLink('/pages/order/list/list?status=1')">
						<view class="order-icon">
							<text v-if="orderNum.readyDelivery > 99" class="order-num">99+</text>
							<text v-else-if="orderNum.readyDelivery > 0"
								class="order-num">{{ orderNum.readyDelivery }}</text>
							<!-- <text class="iconfont">&#xe675;</text> -->
							<image :src="$util.img('upload/uniapp/member/daifahuo.png')" mode="aspectFill"></image>

						</view>
						<text class="order-name">待发货</text>
					</view>
					<view class="order-item" @click="redirectToLink('/pages/order/list/list?status=2')">
						<view class="order-icon">
							<text v-if="orderNum.waitDelivery > 99" class="order-num">99+</text>
							<text v-else-if="orderNum.waitDelivery > 0"
								class="order-num">{{ orderNum.waitDelivery }}</text>
							<!-- <text class="iconfont">&#xe674;</text> -->
							<image :src="$util.img('upload/uniapp/member/daishouhuo.png')" mode="aspectFill"></image>

						</view>
						<text class="order-name">待收货</text>
					</view>
					<view class="order-item" @click="redirectToLink('/pages/order/list/list?status=3')">
						<view class="order-icon">
							<!-- <text class="iconfont">&#xe6d3;</text> -->
							<image :src="$util.img('upload/uniapp/member/yifahuo.png')" mode="aspectFill"></image>
						</view>
						<text class="order-name">已发货</text>
					</view>
					
					<view class="order-item" @click="redirectToLink('/pages/order/list/list?status=4')">
						<view class="order-icon">
							<text v-if="orderNum.refunding > 99" class="order-num">99+</text>
							<text v-else-if="orderNum.refunding > 0" class="order-num">{{ orderNum.refunding }}</text>
							<image :src="$util.img('upload/uniapp/member/tuikuan.png')" mode="aspectFill"></image>
					
						</view>
						<text class="order-name">已完成</text>
					</view>
					
					<!-- <view class="order-item" @click="redirectToLink('/pages/order/list/list?status=-1')">
						<view class="order-icon">
							<text v-if="orderNum.refunding > 99" class="order-num">99+</text>
							<text v-else-if="orderNum.refunding > 0" class="order-num">{{ orderNum.refunding }}</text>
							<image :src="$util.img('upload/uniapp/member/tuikuan.png')" mode="aspectFill"></image>

						</view>
						<text class="order-name">退款/售后</text>
					</view> -->
				</view>
			</view>
			<view class="distribution-section" v-if="addonIsExit.is_exit_fx">
				<template v-if="shopConfig != null && shopConfig.is_distribution_enable == 1">
					<navigator v-if="promoterInfo == null" class="distribution-head"
						url="/distributionpages/apply_promoter/apply_promoter">
						<text class="distribution-tit">推广中心</text>
						<text class="distribution-tip">立即申请</text>
						<text class="distribution-more iconfont">&#xe6a3;</text>
					</navigator>
					<view class="distribution-head" v-else-if="promoterInfo != null && promoterInfo.is_lock == 1"
						@click="toast('该账户被冻结')">
						<text class="distribution-tit">推广中心</text>
						<text class="distribution-more iconfont">&#xe6a3;</text>
					</view>
					<navigator v-else class="distribution-head" url="/distributionpages/index/index">
						<text class="distribution-tit">推广中心</text>
						<text class="distribution-more iconfont">&#xe6a3;</text>
					</navigator>
				</template>
			</view>
			<view class="example-body" style="margin-bottom: 80rpx;">
				<!-- <view v-for="(item, index) in entranceManage" @click="redirectToLink(item.url)">{{item.title}}</view> -->
				<uni-grid :column="4" :show-border="false" :square="false">
					<block v-for="(item, index) in entranceManage" :key="index">
						<view class="">

						</view>
						<view @click="redirectToLink(item.url)" v-if="addonIsExit.is_exit_sign && item.title == '签到'">
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>
						<view @click="redirectToLink(item.url)"
							v-else-if="addonIsExit.is_exit_pintuan && item.title == '我的拼单'">
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>
						<view @click="redirectToLink(item.url)"
							v-else-if="addonIsExit.is_exit_bargain && item.title=='我的砍价'">
							<uni-grid-item>

								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>
						<view @click="redirectToLink(item.url)"
							v-else-if="addonIsExit.is_exit_virtual_goods && item.title=='虚拟码'">
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>
						<view @click="redirectToLink(item.url)"
							v-else-if="addonIsExit.is_exit_pintuan && item.title=='拼团订单'">
							<uni-grid-item>

								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>
						<view @click="redirectToLink(item.url)"
							v-else-if="addonIsExit.is_exit_presell && item.title=='预售订单'">
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>


						<!-- 	<view @click="redirectToLink(item.url)" v-else-if="addonIsExit.is_exit_virtual_goods && isVerification && item.title=='核销台'" >
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view> -->


						<view @click="redirectToLink(item.url)" v-else>
							<uni-grid-item>
								<image class="image" :src="$util.img(item.icon)" mode="aspectFill" />
								<text class="text">{{item.title}}</text>
							</uni-grid-item>
						</view>


					</block>

					<view @click="goPurchase">
						<uni-grid-item>
							<image class="image" src="../../../static/images/purchase.png" mode="aspectFill" />
							<text class="text">我的库存</text>
						</uni-grid-item>
					</view>
					
					<view @click="goyohuui">
						<uni-grid-item>
							<image class="image" src="../../../static/images/purchase.png" mode="aspectFill" />
							<text class="text">优惠券</text>
						</uni-grid-item>
					</view>
<!-- 					<view @click="goAchievement">
						<uni-grid-item>
							<image class="image" src="../../../static/images/achievement.png" mode="aspectFill" />
							<text class="text">商学院成绩</text>
						</uni-grid-item>
					</view> -->
					
					<view @click="cancellation()">
											<uni-grid-item>
												<image class="image" src="../../../static/images/achievement.png" mode="aspectFill" />
												<text class="text">注销账号</text>
											</uni-grid-item>
										</view>
					<view @click="drugInspection">
						<uni-grid-item>
							<image class="image" src="../../../static/images/update.png" mode="aspectFill" />
							<text class="text">质检报告</text>
						</uni-grid-item>
					</view>
					<view @click="mytuiguang">
						<uni-grid-item>
							<image class="image" src="../../../static/images/tuiguang.png" mode="aspectFill" />
							<text class="text">商城二维码</text>
						</uni-grid-item>
					</view>
					
					
					
					<!-- <view @click="clearStorage">
						<uni-grid-item>
							<image class="image" src="../../../static/images/qingli.png" mode="aspectFill" />
							<text class="text">清理缓存</text>
						</uni-grid-item>
					</view> -->

				</uni-grid>
			</view>
			<!-- 我的自定义模块 -->
			<!-- 	<view class="copyright-info" v-if="copyrightLoad > 0">
				<view class="copyright-pic code-pic" v-if="$util.img(bottom_info.copyright_logo)">
					<image :src="$util.img(bottom_info.copyright_logo)" mode="widthFix"></image>
				</view>
				<view class="copyright-pic" v-else>
					<image :src="$util.img('upload/uniapp/member/logo_copy.png')" mode="aspectFit"></image>
				</view>
				<navigator class="copyright-desc" v-if="bottom_info.copyright_companyname" :url="$util.img(bottom_info.copyright_link)">
					{{ bottom_info.copyright_companyname }}
				</navigator>
				<navigator class="copyright-desc" v-else url="http://www.niushop.com.cn">牛酷科技提供技术支持</navigator>
			</view> -->
			<view class="copyright-info">
				<view class="copyright-desc" style="font-size: 30rpx; color: #000000;">
					药王星信息技术有限公司</br>
					联系我们：400-0377-839 </br>
					当前版本是:{{version}}
					<!-- 线上版本是:{{version}} -->
					<!-- 全国服务热线：400-0377-839 -->
				</view>
			</view>

		</view>
		<ns-login ref="login" href="member_index"></ns-login>
	</view>
</template>
<script>
	import http from 'common/js/http.js';
	import uniGrid from '@/components/uni-grid/uni-grid.vue';
	import uniGridItem from '@/components/uni-grid-item/uni-grid-item.vue';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import nsLogin from 'components/ns-login/ns-login.vue';
	let that;
	export default {
		components: {
			uniGrid,
			uniGridItem,
			uniPopup,
			nsLogin
		},
		data() {
			return {
				point:"",
				iconRootPath:"@/static/",
				phone: '',
				bottom_info: {},
				copyrightLoad: '',
				token: '',
				memberInfo: {},
				memberLevelInfo: {
					level_info: {
						level_name: ''
					}
				},
				couponNum: 0,
				memberAccountInfo: {
					balance: '0.00',
					point: 0
				},
				addonIsExit: {},
				isVerification: false,
				code: '',
				orderNum: {
					waitPay: 0, //待付款
					readyDelivery: 0, //待发货
					waitDelivery: 0, //待收货
					refunding: 0 // 退款中
				},
				//推广商信息
				promoterInfo: null,
				shopConfig: null,
				entranceManage: [],
				version: '',
			};
		},
		mixins: [http],
		onLoad(option) {
			this.getCopyright();
			this.checkVerification();
			this.getWapEntranceManage();

			if (option.code) this.code = option.code;
			that = this;
			this.getStorageSize();



		},
		//下拉刷新
		onPullDownRefresh() {
			this.refresh();
		},
		onShow() {
			this.refresh();
		},
		mounted() {

		},
		methods: {
			
			goyohuui(){
				uni.navigateTo({
					url: '/pages/member/coupon/coupon'
				})
			},
			cancellation(){
				var  that =this;
				uni.showModal({
					title: '提示',
					content: '你确定要注销当前账号吗',
					cancelText:'取消',
					confirmText:'确认',
					success(res){
						if(res.confirm){
							that.sendRequest({
								url: 'System.Member.destroyMember',
								data:{
									userId:that.memberInfo.uid
								},
								success: res => {
									if (res.code == 0) {
										
										
										
										uni.showToast({
											title:'注销成功',
											icon:'none'
										})
										uni.removeStorage({
											key: 'token',
											success: res => {
												console.log("5555555555555")
												
												uni.navigateTo({
													url:'/pages/login/login/login'
												})
											}
										});
									}
								}
							});
						}else if(res.cancel){
							console.log('取消')	
						}
					}
				})
			},
			getStorageSize: function() {
				let that = this;
				uni.getStorageInfo({
					success(res) {
						//console.log(res.keys);
						//console.log(res.limitSize);
						let size = res.currentSize;
						if (size < 1024) {
							that.storageSize = size + ' B';
						} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
							that.storageSize = Math.floor(size / 1024 * 100) / 100 + ' KB';
						} else if (size / 1024 / 1024 >= 1) {
							that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + ' M';
						}
					}
				})
			},

			clearStorage() {
				console.log('11111')
				// this.showw = true
				let that = this;
				let os = plus.os.name;
				if (os == 'android') {
					let main = plus.android.runtimeMainActivity();
					let sdRoot = main.getCacheDir();
					let files = plus.android.invoke(sdRoot, "listFiles");
					let len = files.length;
					for (let i = 0; i < len; i++) {
						let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径  
						plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
							if (entry.isDirectory) {
								entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录  
									uni.showToast({
										title: '缓存清理完成',
										duration: 2000
									});
									that.formatSize(); // 重新计算缓存  
								}, function(e) {
									console.log(e.message)
								});
							} else {
								entry.remove();
							}
						}, function(e) {
							console.log('文件路径读取失败')
						});
					}
				} else { // ios  
					plus.cache.clear(function() {
						uni.showToast({
							title: '缓存清理完成',
							duration: 2000
						});
						that.formatSize();
					});
				}
			},
			mytuiguang() {
				uni.navigateTo({
					url: '../../tuigaung/tuigaung'
				})
			},
				drugInspection(){
					uni.navigateTo({
						url:'../../druglnspection/druglnspection'
					})
					
				},
			
			startWgt(){
				
					var iphoneType=uni.getSystemInfoSync().platform;
					plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
						
						console.log("ssssssssssssssssssss",widgetInfo.version.version)
						this.wgtver=widgetInfo.version;
						this.appver=plus.runtime.version;
						uni.setStorageSync('this.version.version_number',widgetInfo.version)
					    uni.request({  
					        url: 'https://yiyaoapp.xihewh.com/api.php?method=System.Member.getlink',  
					        data: {  
					            version: widgetInfo.version,  
					            name: widgetInfo.name  
					        },  
					        success: (result) => {  
					            var data = JSON.parse(result.data);
								//app版本号获取方式
								// let topIconPath=plus.io.convertLocalFileSystemURL(this.iconRootPath)+"/uploadimg.png";			
								// //plus.runtime.version; 与服务器的版本进行比较;
								// const upDater=uni.requireNativePlugin("CL-UpDater");
								// let options={
								// 	title:"升级,有数据需要更新，请点击升级",
								// 	con:"1、修复了登录输入框数据问题;2、优化了模块管理添加和删除卡顿问题",
								// 	// downUrl:iphoneType == 'android' ?'https://yiyaoapp.xihewh.com/'+data.data.link.download_address:'http://itunes.apple.com/cn/app/id1582764341?mt=8',//请设置下载apk地址,ios设置苹果商店的连接地址;
								// 	downUrl:"https://yiyaoapp.xihewh.com/upload/app_upgrade/2021113002353122080.apk",//请设置下载apk地址,ios设置苹果商店的连接地址;
								// 	hidCancelbtn:false,//可选 隐藏取消按钮
								// 	btnBgColor:"#eb423b",//可选 按钮颜色
								// 	updateBtnText:"立即升级",//可选, 升级按钮文字,
								// 	verCode:"1.0.1",//最新apk版本号 可选  只有Android整包升级可以设置这个参数 ,可以避免用户取消安装apk时,重复下载问题,如果不传的话,apk将会重新下载
								// 	hidBackBtn:false, //可选 只有android整包更新才可以控制后台更新按钮是否显示，热更新是不显示这个按钮的   	
								// 	downMsgTip:"资源下载中，请稍后...", //可选(android)
								// 	topImgBg:topIconPath//可选 除非需要自定义头部logo，否则不需要传;
								// }
								// //必需提供下载地址;
								// upDater.startUpdate(options,()=>{
								// 		iphoneType == 'android' ? plus.runtime.quit() : plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
								// 	console.log("弹框关闭了");
												
								// });	
								
					let that=this;
					//注意：服务器的热更新版本号必需大于本地wgt版本号
					let topIconPath=plus.io.convertLocalFileSystemURL(that.iconRootPath)+"/uploadimg.png";
					//第一步要获取本地的wgt版本号；
					const upDater=uni.requireNativePlugin("CL-UpDater");
					let options={
						title:"有数据需要更新，请点击更新",
						con:"版本更新",
						downUrl:iphoneType == 'android' ?'https://yiyaoapp.xihewh.com/'+data.data.link.download_address:'http://itunes.apple.com/cn/app/id1582764341?mt=8',
						hidCancelbtn:false,//可选
						btnBgColor:"#eb423b",//可选
						downMsgTip:"资源下载中，请稍后...", //可选
						updateBtnText:"升级",//可选 升级按钮文字,
						topImgBg:topIconPath,//可选 除非需要自定义头部logo，否则不需要传;
					}
					//第一步创建文件下载路径，并创建文件;
					plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS,function(fobject){
						//设置文件下载根路径;	
						let rootPath=fobject.root.fullPath;	
						upDater.wgtUpdate(options,rootPath,result=>{
							if(result)
							{
								var pathNew = plus.io.convertAbsoluteFileSystem(result);
								console.log(pathNew);
								plus.runtime.install(pathNew, {
									force: false
								}, function() {
									//进行重新启动;
									plus.runtime.restart();
								}, (e) => {
									uni.showToast({
										title: '安装升级包失败'+JSON.stringify(e),
										icon: 'none'
									})								
									
								});
								
							}
										
						},()=>{
							iphoneType == 'android' ? plus.runtime.quit() : plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
							console.log("弹框关闭了");
						});
					})
					        }  
					    });  
					});  
					
					
				
				// var iphoneType=uni.getSystemInfoSync().platform;
				// //注意：服务器的热更新版本号必需大于本地wgt版本号
				// //http://192.168.50.201/update.wgt,
				// let topIconPath=plus.io.convertLocalFileSystemURL(this.iconRootPath)+"/uploadImg.png";		
				// let that=this;
				// //第一步要获取本地的wgt版本号；
				// const upDater=uni.requireNativePlugin("CL-UpDater");
				// let options={
				// 	title:"升级,有数据需要更新，请点击升级",
				// 	con:"1、修复了登录输入框数据问题;2、优化了模块管理添加和删除卡顿问题",
				// 	downUrl:iphoneType == 'android' ?"https://yiyaoapp.xihewh.com/upload/app_upgrade/47.wgt":'http://itunes.apple.com/cn/app/id1582764341?mt=8',
				// 	hidCancelbtn:false,//可选
				// 	btnBgColor:"#587dff",//可选
				// 	downMsgTip:"资源下载中，请稍后...", //可选
				// 	updateBtnText:"升级",//可选 升级按钮文字,
				// 	topImgBg:topIconPath,//可选 除非需要自定义头部logo，否则不需要传;
				// }
				// //第一步创建文件下载路径，并创建文件;
				// plus.io.requestFileSystem(plus.io.PUBLIC_DOWNLOADS,function(fobject){
					
				// 	//设置文件下载根路径;	
				// 	let rootPath=fobject.root.fullPath;	
				// 	upDater.wgtUpdate(options,rootPath,result=>{
						
				// 		if(result)
				// 		{
				// 			var pathNew = plus.io.convertAbsoluteFileSystem(result);
				// 			console.log(pathNew);
						
				// 			plus.runtime.install(pathNew, {
				// 				force: false
				// 			}, function() {
								
				// 				//进行重新启动;
				// 				plus.runtime.restart();
								
																								
				// 			}, (e) => {
												
				// 				uni.showToast({
				// 					title: '安装升级包失败'+JSON.stringify(e),
				// 					icon: 'none'
				// 				})								
								
				// 			});
							
				// 		}
									
				// 	},()=>{
					
				// 		uni.getSystemInfoSync().platform == 'android' ? plus.runtime.quit() : plus.ios.import("UIApplication").sharedApplication().performSelector("exit");
				// 		console.log("弹框关闭了");
				// 	});
				// })
						
			},
			
			myupdate() {
					// #ifdef APP-PLUS  
					plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {  
						uni.setStorageSync('this.version.version_number', widgetInfo.version)
						console.log("version=====================",widgetInfo.version)
						console.log("name=====================",widgetInfo.name)
					    uni.request({  
					        url: 'https://yiyaoapp.xihewh.com/api.php?method=System.Member.getlink',  
					        data: {  
					            version: widgetInfo.version,  
					            name: widgetInfo.name  
					        },  
					        success: (result) => {  
					            var data = JSON.parse(result.data);
								  console.log("data-------------------",data.data.link)
					            if (data.data.link.version_number && data.data.link.download_address) {
									console.log("进来了========================")
					                uni.downloadFile({  
					                    url:'https://yiyaoapp.xihewh.com/'+data.data.link.download_address, 
					                    success: (downloadResult) => {  
					                        if (downloadResult.statusCode === 200) {  
												console.log("200==============",downloadResult)
					                            plus.runtime.install(downloadResult.tempFilePath, {  
					                                force: false  
					                            }, function() {  
					                                console.log('install success...');  
					                                plus.runtime.restart();  
					                            }, function(e) {  
					                                console.error('install fail...');  
					                            });  
					                        }  
					                    }  
					                });  
					            }  
					        }  
					    });  
					});  
					// #endif
					// uni.request({
					// 	url: 'https://yiyaoapp.xihewh.com/api.php?method=System.Member.getlink',
					// 	data: {},
					// 	success: (result) => {
					// 		console.log("result============", JSON.parse(result.data))
					// 		// 如果后台传来的版本号和本机的版本号不一样,并且本机的版本号<后台传来的版本号  提示更新
					// 		if (widgetInfo.version != JSON.parse(result.data).data.link
					// 			.version_number && JSON.parse(result.data).data.link.version_number >
					// 			widgetInfo.version) {
					// 			uni.showModal({ //提醒用户更新
					// 				title: "有新版本可以更新",
					// 				content: "你确定要升级当前应用吗？",
					// 				showCancel: false,
					// 				success: (res) => {
					// 					if (res.confirm) {
					// 						let url = 'https://yiyaoapp.xihewh.com/' + JSON
					// 							.parse(result.data).data.link
					// 							.download_address
					// 						plus.runtime.openURL(url);
					// 					}
					// 					if (res.cancel) {
					// 						let url = 'https://yiyaoapp.xihewh.com/' + JSON
					// 							.parse(result.data).data.link
					// 							.download_address
					// 						plus.runtime.openURL(url);
					// 					}
					// 				},

					// 			})

					// 		} else {
					// 			uni.showToast({
					// 				title: '暂时没有新版本可以更新',
					// 				icon: 'none',
					// 				duration: 3000
					// 			})
					// 		}
					// 	}
					// });
			},
			goAchievement() {
				uni.navigateTo({
					url: '/pages/member/achievement/achievement?phone=' + this.phone
				})
			},
			goPurchase() {
				uni.navigateTo({
					url: '/pages/member/purchase/purchase'
				})
			},
			tosao() {
				console.log('扫一扫')
			},
			// 请求数据
			async refresh() {

				this.token = uni.getStorageSync('token');
				this.version = uni.getStorageSync('this.version.version_number');
				if (this.token) this.getMemberInfo();
				else this.initInfo();

				let res = await this.sendRequest({
					url: 'System.Config.addonIsExit',
					async: false
				});

				if (res.code == 0) {

					this.addonIsExit = res.data;
					console.log('this.addonIsExit=', this.addonIsExit)
					if (this.token && this.addonIsExit.is_exit_fx) {
						this.getPromoterDetail();
						this.getShopConfig();
					}
				}
			},

			/**
			 * 个人中心入口栏目
			 */
			getWapEntranceManage() {
				this.sendRequest({
					url: 'System.Config.wapEntrance',
					data: {
						port: 2
					},
					success: res => {
						console.log("个人中心入口栏目res=============", res)
						if (res.code == 0) {

							this.entranceManage = res.data;
						}
					}
				});
			},

			/**
			 * 初始化数据
			 */
			initInfo() {
				this.couponNum = 0;
				this.memberAccountInfo = {
					balance: '0.00',
					point: 0
				};
				this.orderNum = {
					waitPay: 0, //待付款
					readyDelivery: 0, //待发货
					waitDelivery: 0, //待收货
					refunding: 0 // 退款中
				};
				this.promoterInfo = null;
				this.shopConfig = null;
				this.isVerification = false;
				this.addonIsExit = {};
				this.memberInfo = {};
				this.memberLevelInfo = {
					level_info: {
						level_name: ''
					}
				};
				uni.stopPullDownRefresh();
			},
			/**
			 * 订单数量
			 */
			getOrderNum() {
				this.sendRequest({
					url: 'System.Order.orderCount',
					data: {
						order_status: 0
					},
					success: res => {
						if (res.code == 0) {
							this.orderNum.waitPay = res.data;
						}
					}
				});
				this.sendRequest({
					url: 'System.Order.orderCount',
					data: {
						order_status: 1
					},
					success: res => {
						if (res.code == 0) {
							this.orderNum.readyDelivery = res.data;
						}
					}
				});
				this.sendRequest({
					url: 'System.Order.orderCount',
					data: {
						order_status: 2
					},
					success: res => {
						if (res.code == 0) {
							this.orderNum.waitDelivery = res.data;
						}
					}
				});
				this.sendRequest({
					url: 'System.Order.orderCount',
					data: {
						order_status: -1
					},
					success: res => {
						if (res.code == 0) {
							this.orderNum.refunding = res.data;
						}
					}
				});
			},
			/**
			 * 检测是否登录
			 */
			redirectToLink(url) {
				var isLogin = true;
				// #ifdef MP
				getApp().$vm.checkLogin(() => {
					isLogin = false;
					this.clickLogin();
				});
				// #endif
				// #ifdef H5
				getApp().checkLogin(() => {
					isLogin = false;
					this.clickLogin();
				});
				// #endif
				if (isLogin) this.$util.redirectTo(url);
			},
			/**
			 * 版权信息
			 */
			getCopyright() {
				this.sendRequest({
					url: 'System.Config.copyRight',
					success: res => {
						this.copyrightLoad = res.data.is_load;
						this.bottom_info = res.data.bottom_info;
					}
				});
			},
			/**
			 * 获取用户核销身份
			 */
			checkVerification() {
				this.sendRequest({
					url: 'System.Order.checkVerification',
					success: res => {
						if (res.data != null) {
							this.isVerification = true;
						}
					}
				});
			},
			/**
			 * 获取用户信息
			 */
			getMemberInfo() {
				this.sendRequest({
					url: 'System.Member.memberInfo',
					success: res => {
						console.log("sssssssssss",res.data)
						this.phone = res.data.user_info.user_tel
						this.point=res.data.point
						if (res.code == 0 && res.data) {
							this.memberInfo = res.data.user_info;
							this.memberLevelInfo.level_id = res.data.member_level;
							uni.setStorageSync('userType',res.data.userType)
							this.getMemberLevelInfo();
							this.getMemberCoupon();
							this.getMemberAccountInfo();
							this.getOrderNum();
						}
					}
				});
			},
			/**
			 * 获取会员等级信息
			 */
			getMemberLevelInfo() {
				this.sendRequest({
					url: 'System.Member.memberLevel',
					data: {
						level_id: this.memberLevelInfo.level_id
					},
					success: res => {
						if (res.code == 0) {
							this.memberLevelInfo.level_info = res.data;
						}
					}
				});
			},
			/**
			 * 获取会员优惠券数量
			 */
			getMemberCoupon() {
				this.sendRequest({
					url: 'System.Member.couponNum',
					data: {
						level_id: this.memberLevelInfo.level_id
					},
					success: res => {
						if (res.code == 0) {
							this.couponNum = res.data;
						}
					}
				});
			},
			/**
			 * 获取会员账户信息
			 */
			getMemberAccountInfo() {
				this.sendRequest({
					url: 'System.Member.memberAccount',
					success: res => {
						if (res.code == 0) {
							this.memberAccountInfo = res.data;
							uni.stopPullDownRefresh();
						}
					}
				});
			},
			clickLogin() {
				console.log(22)
				this.$refs.login.clickLogin();
			},
			/**
			 * 获取推广商信息
			 */
			getPromoterDetail() {
				this.sendRequest({
					url: 'Nsfx.Distribution.promoterDetail',
					success: res => {
						if (res.code == 0) {
							this.promoterInfo = res.data;
						} else {
							this.promoterInfo = null;
						}
					}
				});
			},
			/**
			 * 店铺推广设置
			 */
			getShopConfig() {
				this.sendRequest({
					url: 'System.Distribution.shopConfig',
					success: res => {
						if (res.code == 0) {
							this.shopConfig = res.data;
						}
					}
				});
			},
			toast(msg) {
				this.$util.showToast({
					title: msg
				});
			}
		}
	};
</script>
<style lang="scss">
	%flex-row-centered {
		display: flex;
		justify-content: space-around;
		align-items: center;
	}

	%flex-column-centered {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%flex-list {
		display: flex;
		justify-content: space-between;
		padding: 0 30rpx;
		height: 100rpx;
		line-height: 100rpx;
	}

	.user-section {
		padding: 10rpx 30rpx 0;
		// position: relative;
		/*  #ifdef MP */
		padding: 150rpx 30rpx 0;
		/* #endif */
		/*  #ifdef H5 || MP-ALIPAY*/
		//height: 300rpx;
		padding: 70rpx 50rpx 0;
		/* #endif */
		box-sizing: border-box;
		//background: linear-gradient(to right, #ff0137 ,#fb3364);
		background: url() center no-repeat;
		background-size: 100% 100%;

		.member-sction {
			margin-top: 20rpx;
			padding: 0rpx 40rpx;

			.sction-item {
				color: #fff;
			}

			.shu {
				height: 60rpx;
				width: 2rpx;
				background: #fe94ac;
				display: inline-block;
			}
		}

		.member-equity {
			background: #1d1d1d;
			height: 65rpx;
			border-radius: 17rpx 17rpx 0rpx 0rpx;
			display: block;
			width: 100%;
			margin-top: 12rpx;
			overflow: hidden;
			position: relative;
			line-height: 65rpx;

			.member-level {
				color: #d6ca94;
				font-size: 24rpx;
				margin-left: 72rpx;
			}

			.level-img {
				background: url() center no-repeat;
				background-size: 100% 100%;
				width: 30rpx;
				height: 30rpx;
				position: absolute;
				top: 19rpx;
				left: 30rpx;
			}

			.iconfont {
				float: right;
				font-size: 24rpx;
				color: #d6ca94;
				position: relative;
				padding-right: 30rpx;
				right: 17rpx;
			}

			.iconright:before {
				position: absolute;
				right: 0rpx;
			}
		}

		.user-info-box {
			padding-top: 40rpx;
			display: flex;
			align-items: flex-start;

			&.no-log {
				flex-direction: row-reverse;
				justify-content: space-between;

				.user-title {
					font-size: $uni-font-size-lg + 16rpx;
					color: #fff;
					line-height: 1.2;
				}

				.user-desc {
					border: none !important;
					font-size: $uni-font-size-base !important;
					color: #fff !important;
					padding: 0 !important;
				}
			}

			.user-head {
				box-sizing: content-box;
				margin-top: 20rpx;
				margin-left: 20rpx;
				width: 120rpx;
				height: 120rpx;
				border: 6rpx solid #fff;
				border-radius: 50%;
				overflow: hidden;

				image {
					width: 120rpx;
					height: 120rpx;
					vertical-align: middle;
				}
			}

			.user-box {
				max-width: 45%;
				margin-left: 20rpx;
				overflow: hidden;

				text {
					display: block;
					max-width: 300rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					font-size: 36rpx;
					color: #fff;

					&:last-of-type {
						padding: 6rpx 10rpx;
						font-size: $ns-font-size-lg;
						color: #fff;
					}
				}

				.user-label {
					display: inline-block;
					max-width: 90%;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
					color: #e7e525;
					text-align: center;
					// border: 2rpx solid #e7e525;
					border-radius: 30px;
					font-size: $ns-font-size-sm;
					padding: 8rpx 18rpx;
					line-height: 1;
					background: #c4002a;
					color: #fff;
				}
			}
		}

		.user-set {
			position: absolute;
			// width: 80rpx;
			height: 40rpx;
			right: 30rpx;
			top: 70rpx;
			/* #ifdef  MP*/
			top: 158rpx;
			/* #endif */
			/* #ifdef  H5 || MP-ALIPAY*/
			top: 50rpx;

			/* #endif */
			image {
				max-height: 40rpx;
				max-width: 40rpx;
			}
		}

		.member-sign {
			position: absolute;
			display: flex;
			align-items: center;
			width: 204rpx;
			height: 76rpx;
			right: 0;
			/* #ifdef  MP*/
			top: 240rpx;
			/* #endif */
			/* #ifdef  H5 || MP-ALIPAY*/
			top: 120rpx;
			/* #endif */
			border-top-left-radius: 100rpx;
			border-bottom-left-radius: 100rpx;
			box-shadow: -3px 5px 11px rgba(0, 0, 0, 0.2);

			image {
				width: 48rpx;
				height: 48rpx;
				margin-left: 20rpx;
				margin-right: 10rpx;
			}

			.member-sign-body {
				display: flex;
				flex-direction: column;
				align-content: center;
				line-height: 1;
			}

			.member-sign-name {
				margin-bottom: 10rpx;
				font-size: $ns-font-size-base;
				font-weight: 600;
			}

			.member-sign-desc {
				font-size: $ns-font-size-sm;
			}
		}
	}

	.member-body {
		position: relative;
	}

	.member-sction {
		@extend %flex-row-centered;
		height: 140rpx;
		border-radius: 10rpx;

		.sction-item {
			@extend %flex-column-centered;

			text {
				font-size: $ns-font-size-base;
			}

			.num {
				font-size: $ns-font-size-lg + 8rpx;
			}
		}
	}

	.order-section {
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;

		.order-head {
			@extend %flex-list;
			border: none;

			.order-tit {
				font-size: $ns-font-size-lg + 4rpx;
			}

			.order-tip {
				margin-left: auto;
				margin-right: 6rpx;
				color: lighten($ns-text-color-gray, 10%);
			}

			.order-more {
				color: lighten($ns-text-color-gray, 10%);
				font-size: $ns-font-size-sm;
			}
		}

		.order-body {
			@extend %flex-row-centered;
			height: 176rpx;
			box-sizing: border-box;

			.order-item {
				@extend %flex-column-centered;

				.order-icon {
					position: relative;
					line-height: 1;
					width: 50rpx;
					height: 50rpx;

					image {
						width: 100%;
						height: 100%;
					}

					.order-num {
						position: absolute;
						top: -12rpx;
						right: -14rpx;
						width: 30rpx;
						height: 30rpx;
						font-size: $ns-font-size-sm;
						line-height: 30rpx;
						text-align: center;
						color: #fff;
						padding: 6rpx;
						background-color: $base-color;
						border-radius: 50%;
						z-index: 1;
					}

					.iconfont {
						font-size: $ns-font-size-lg + 16rpx;
					}
				}

				.order-name {
					margin-top: 10rpx;
					color: darken($ns-text-color-gray, 15%);
				}
			}
		}
	}

	.distribution-section {
		margin-top: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;

		.distribution-head {
			@extend %flex-list;
			border: none;

			.distribution-tip {
				margin-left: auto;
				margin-right: 6rpx;
				color: darken($ns-text-color-gray, 15%);
			}

			.distribution-tit {
				font-size: $ns-font-size-lg + 4rpx;
			}

			.iconfont {
				color: lighten($ns-text-color-gray, 10%);
				font-size: $ns-font-size-sm;
			}
		}

		.distribution-body {
			@extend %flex-row-centered;
			height: 160rpx;
			box-sizing: border-box;

			.distribution-item {
				@extend %flex-column-centered;

				.num {
					font-size: $ns-font-size-lg + 8rpx;
					line-height: 1;
				}

				.name {
					margin-top: 10rpx;
					color: lighten($ns-text-color-gray, 10%);
				}
			}
		}
	}

	.example-body {
		margin-top: 20rpx;
		padding: 30rpx 6rpx;
		background: #fff;
	}

	.example-body1 {

		background: #fff;
	}

	.image {
		width: 60rpx;
		height: 60rpx;
	}

	.text {
		font-size: 26rpx;
		margin-top: 10rpx;
	}

	.copyright-info {
		margin-bottom: 40rpx;
		/* #ifdef MP-WEIXIN */
		margin-bottom: 40rpx;
		/* #endif */
		@extend %flex-column-centered;

		.copyright-pic {
			width: 180rpx;
			margin: auto;

			image {
				width: 100%;
			}

			.code-pic.copyright-pic {
				height: 180rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		text {
			font-size: $ns-font-size-sm;
			height: 100rpx;
			line-height: 100rpx;
			color: $ns-text-color-gray;
		}

		.copyright-desc {
			color: lighten($ns-text-color-gray, 30%);
			font-size: $ns-font-size-sm;
			text-shadow: 0 0 1px lighten($ns-text-color-gray, 40%);
		}
	}

	.member-adv {
		display: flex;
		justify-content: space-between;
		margin-top: 20rpx;
		height: 152rpx;
		box-sizing: border-box;
		border-radius: 10rpx;
		padding: 0rpx 25rpx;

		>navigator {
			position: relative;
			width: 344rpx;

			image {
				display: block;
				max-width: 100%;
				max-height: 100%;
			}
		}
	}
</style>
